﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.IO
Imports Contracts
Imports Entities

Public Class GetImage
	Inherits Albatross.ServerSide.Messaging.RequestHandler(Of GetImageI)

	Public Overloads Overrides Function Handle(ByVal request As Contracts.GetImageI) As Albatross.Common.Messaging.Response
		Dim oResponse As GetImageO
		Dim oFile As FileInfo
		Dim cFILENAME As String = "C:\vss\AlbatrossFramework\Samples\VB\WebHost\bin\project.jpg"
		Dim oFileStream As FileStream
		Dim lFileStreamLength As Long = 0
		Dim oBytes(1) As Byte

		oResponse = New GetImageO
		oResponse.ImageByteArray = Nothing

		oFile = New FileInfo(cFILENAME)
		oFileStream = oFile.OpenRead()
		lFileStreamLength = oFileStream.Length
		If (lFileStreamLength > 0) Then
			ReDim oBytes(lFileStreamLength - 1)
			oFileStream.Read(oBytes, 0, lFileStreamLength)	' Read the file into a byte array
			oFileStream.Close()

			ReDim oResponse.ImageByteArray(lFileStreamLength)
			oResponse.ImageByteArray = oBytes
		End If

		Return oResponse
	End Function
End Class
